import logging
import time
from fastapi import Request

async def record_time_middleware(request: Request, call_next):
    start_time = time.time()
    response = await call_next(request)
    process_time = time.time() - start_time
    response.headers["X-Process-Time"] = str(process_time)
    logging.debug(f"Request: {request.method} {request.url}. process: {process_time:.4f} seconds")
    return response